//
//  ViewController.m
//  UI04_ZombieOfSliderHomework
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createImageView];
    [self createAnimationImage1];
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 100, 200, 50)];
    [self.view addSubview:slider];
    UIImageView *imageView = [self.view viewWithTag:100];
    imageView.animationDuration = 0.99;
    [imageView startAnimating];
    slider.minimumValue = 0.01;
    slider.maximumValue = 0.9;
    [slider addTarget:self action:@selector(changeSpeed:) forControlEvents:UIControlEventValueChanged];

}
-(void)changeSpeed:(UISlider *)slider{
    UIImageView *imageView = [self.view viewWithTag:100];
    [imageView stopAnimating];
    imageView.animationDuration = 1 - slider.value;
    [imageView startAnimating];
}

-(void)createImageView {
    UIImage *image = [UIImage imageNamed:@"BackGround.png"];
    UIImageView *backgroundImageView =[[UIImageView alloc] initWithImage:image];
    backgroundImageView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:backgroundImageView];
    [backgroundImageView release];
}

-(void)createAnimationImage1{
    UIImageView *animationImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BZombie1.tiff"]];
    animationImageView.tag = 100;
    animationImageView.frame = CGRectMake(200, 100, 200, 200);
    
    [self.view addSubview:animationImageView];
    [animationImageView release];
    
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:25];
    
    for (int i = 1;i <= 25;i++){
        NSString *name = [NSString stringWithFormat:@"BZombie%d.tiff",i];
        UIImage *animationImage  = [UIImage imageNamed:name];
        
        [mutableArray addObject:animationImage];
    }
    
    
    animationImageView.animationImages = mutableArray;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
